package com.uc3m.dsic.gestorZoo;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JOptionPane;

/**
 * Clase que va a ejecutar el menú de las consultas y que contendrá tanto
 * cómo será la GUI como la ejecución de cada una de ellas.
 *
 * @author Javier Roca García
 */
public class Consultas extends javax.swing.JFrame {

    /** Creates new form NewJFrame */
    public Consultas() {
        initComponents(); 
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane3 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        tabConsulta4 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        bConsulta1 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        bConsulta2 = new javax.swing.JButton();
        tbConsulta2Cuidador = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        tbConsulta3Zoo = new javax.swing.JTextField();
        bConsulta3 = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel27 = new javax.swing.JLabel();
        tbConsulta4Zoo = new javax.swing.JTextField();
        bConsulta4 = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jLabel35 = new javax.swing.JLabel();
        tbConsulta5Zoo = new javax.swing.JTextField();
        bConsulta5 = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel38 = new javax.swing.JLabel();
        tbConsulta6Ciudad = new javax.swing.JTextField();
        bConsulta6 = new javax.swing.JButton();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jLabel48 = new javax.swing.JLabel();
        tbConsulta7Especialidad = new javax.swing.JTextField();
        bConsulta7 = new javax.swing.JButton();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jPanel10 = new javax.swing.JPanel();
        jLabel49 = new javax.swing.JLabel();
        tbConsulta8Pais = new javax.swing.JTextField();
        bConsulta8 = new javax.swing.JButton();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        bIrGestorTablas = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tabConsulta4.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 28));
        jLabel8.setText("Consulta 1");

        bConsulta1.setFont(new java.awt.Font("Tahoma", 0, 14));
        bConsulta1.setText("Consultar");
        bConsulta1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bConsulta1ActionPerformed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel9.setText("Número de plazas que quedan libres en cada sala y en cada zoo");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(64, 64, 64))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(402, Short.MAX_VALUE)
                .addComponent(bConsulta1)
                .addGap(144, 144, 144))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 581, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9)
                .addGap(56, 56, 56)
                .addComponent(bConsulta1)
                .addGap(174, 174, 174))
        );

        tabConsulta4.addTab("C-0001", jPanel3);

        bConsulta2.setFont(new java.awt.Font("Tahoma", 0, 14));
        bConsulta2.setText("Consultar");
        bConsulta2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bConsulta2ActionPerformed(evt);
            }
        });

        tbConsulta2Cuidador.setFont(new java.awt.Font("Tahoma", 0, 14));
        tbConsulta2Cuidador.setMaximumSize(new java.awt.Dimension(72, 23));
        tbConsulta2Cuidador.setMinimumSize(new java.awt.Dimension(72, 23));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText("Identificador Cuidador");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 28));
        jLabel10.setText("Consulta 2");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel11.setText("Animales que debe alimentar un cuidador y con qué comida");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(37, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(37, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(107, 107, 107)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(tbConsulta2Cuidador, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(109, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(441, Short.MAX_VALUE)
                .addComponent(bConsulta2)
                .addGap(78, 78, 78))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tbConsulta2Cuidador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addComponent(bConsulta2)
                .addContainerGap(38, Short.MAX_VALUE))
        );

        tabConsulta4.addTab("C-0002", jPanel2);

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel18.setText("Zoo");

        tbConsulta3Zoo.setFont(new java.awt.Font("Tahoma", 0, 14));
        tbConsulta3Zoo.setMaximumSize(new java.awt.Dimension(72, 23));
        tbConsulta3Zoo.setMinimumSize(new java.awt.Dimension(72, 23));

        bConsulta3.setFont(new java.awt.Font("Tahoma", 0, 14));
        bConsulta3.setText("Consultar");
        bConsulta3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bConsulta3ActionPerformed(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 28));
        jLabel12.setText("Consulta 3");

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel13.setText("Animales que hay en un zoo y dónde se encuentran");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(37, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(118, Short.MAX_VALUE)
                .addComponent(jLabel18)
                .addGap(42, 42, 42)
                .addComponent(tbConsulta3Zoo, javax.swing.GroupLayout.PREFERRED_SIZE, 314, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(109, 109, 109))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(453, Short.MAX_VALUE)
                .addComponent(bConsulta3)
                .addGap(66, 66, 66))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tbConsulta3Zoo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18))
                .addGap(18, 18, 18)
                .addComponent(bConsulta3)
                .addGap(173, 173, 173))
        );

        tabConsulta4.addTab("C-0003", jPanel4);

        jLabel27.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel27.setText("Zoo");

        tbConsulta4Zoo.setFont(new java.awt.Font("Tahoma", 0, 14));
        tbConsulta4Zoo.setMaximumSize(new java.awt.Dimension(72, 23));
        tbConsulta4Zoo.setMinimumSize(new java.awt.Dimension(72, 23));

        bConsulta4.setFont(new java.awt.Font("Tahoma", 0, 14));
        bConsulta4.setText("Consultar");
        bConsulta4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bConsulta4ActionPerformed(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 28));
        jLabel14.setText("Consulta 4");

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel15.setText("Entradas que quedan por vender en un zoo");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(37, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(460, Short.MAX_VALUE)
                .addComponent(bConsulta4)
                .addGap(59, 59, 59))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(132, Short.MAX_VALUE)
                .addComponent(jLabel27)
                .addGap(46, 46, 46)
                .addComponent(tbConsulta4Zoo, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(129, 129, 129))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15)
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tbConsulta4Zoo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel27))
                .addGap(18, 18, 18)
                .addComponent(bConsulta4)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        tabConsulta4.addTab("C-0004", jPanel5);

        jLabel35.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel35.setText("Zoo");

        tbConsulta5Zoo.setFont(new java.awt.Font("Tahoma", 0, 14));
        tbConsulta5Zoo.setMaximumSize(new java.awt.Dimension(72, 23));
        tbConsulta5Zoo.setMinimumSize(new java.awt.Dimension(72, 23));

        bConsulta5.setFont(new java.awt.Font("Tahoma", 0, 14));
        bConsulta5.setText("Consultar");
        bConsulta5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bConsulta5ActionPerformed(evt);
            }
        });

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 28));
        jLabel16.setText("Consulta 5");

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel17.setText("Número de salas que tiene un zoo");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(37, Short.MAX_VALUE))
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(153, 153, 153)
                .addComponent(jLabel35)
                .addGap(18, 18, 18)
                .addComponent(tbConsulta5Zoo, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(147, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(444, Short.MAX_VALUE)
                .addComponent(bConsulta5)
                .addGap(75, 75, 75))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel17)
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel35)
                    .addComponent(tbConsulta5Zoo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(bConsulta5)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        tabConsulta4.addTab("C-0005", jPanel6);

        jLabel38.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel38.setText("Ciudad");

        tbConsulta6Ciudad.setFont(new java.awt.Font("Tahoma", 0, 14));
        tbConsulta6Ciudad.setMaximumSize(new java.awt.Dimension(72, 23));
        tbConsulta6Ciudad.setMinimumSize(new java.awt.Dimension(72, 23));

        bConsulta6.setFont(new java.awt.Font("Tahoma", 0, 14));
        bConsulta6.setText("Consultar");
        bConsulta6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bConsulta6ActionPerformed(evt);
            }
        });

        jLabel19.setFont(new java.awt.Font("Tahoma", 1, 28));
        jLabel19.setText("Consulta 6");

        jLabel20.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel20.setText("Zoos que están en una determinada ciudad");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(37, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap(454, Short.MAX_VALUE)
                .addComponent(bConsulta6)
                .addGap(65, 65, 65))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap(121, Short.MAX_VALUE)
                .addComponent(jLabel38)
                .addGap(18, 18, 18)
                .addComponent(tbConsulta6Ciudad, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(111, 111, 111))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jLabel19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel20)
                .addGap(18, 18, 18)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tbConsulta6Ciudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel38))
                .addGap(18, 18, 18)
                .addComponent(bConsulta6)
                .addContainerGap(34, Short.MAX_VALUE))
        );

        tabConsulta4.addTab("C-0006", jPanel7);

        jLabel48.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel48.setText("Especialidad");

        tbConsulta7Especialidad.setFont(new java.awt.Font("Tahoma", 0, 14));
        tbConsulta7Especialidad.setMaximumSize(new java.awt.Dimension(72, 23));
        tbConsulta7Especialidad.setMinimumSize(new java.awt.Dimension(72, 23));

        bConsulta7.setFont(new java.awt.Font("Tahoma", 0, 14));
        bConsulta7.setText("Consultar");
        bConsulta7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bConsulta7ActionPerformed(evt);
            }
        });

        jLabel21.setFont(new java.awt.Font("Tahoma", 1, 28));
        jLabel21.setText("Consulta 7");

        jLabel22.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel22.setText("Cuidadores de Animales que tienen una determinada especialidad");

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel22)
                    .addComponent(jLabel21, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap(450, Short.MAX_VALUE)
                .addComponent(bConsulta7)
                .addGap(72, 72, 72))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap(146, Short.MAX_VALUE)
                .addComponent(jLabel48)
                .addGap(18, 18, 18)
                .addComponent(tbConsulta7Especialidad, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(123, 123, 123))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel21)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel22)
                .addGap(18, 18, 18)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tbConsulta7Especialidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel48))
                .addGap(18, 18, 18)
                .addComponent(bConsulta7)
                .addContainerGap(32, Short.MAX_VALUE))
        );

        tabConsulta4.addTab("C-0007", jPanel9);

        jLabel49.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel49.setText("País");

        tbConsulta8Pais.setFont(new java.awt.Font("Tahoma", 0, 14));
        tbConsulta8Pais.setMaximumSize(new java.awt.Dimension(72, 23));
        tbConsulta8Pais.setMinimumSize(new java.awt.Dimension(72, 23));

        bConsulta8.setFont(new java.awt.Font("Tahoma", 0, 14));
        bConsulta8.setText("Consultar");
        bConsulta8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bConsulta8ActionPerformed(evt);
            }
        });

        jLabel23.setFont(new java.awt.Font("Tahoma", 1, 28));
        jLabel23.setText("Consulta 8");

        jLabel24.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel24.setText("Animales que proceden de un determinado país");

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel24)
                    .addComponent(jLabel23, javax.swing.GroupLayout.PREFERRED_SIZE, 563, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(37, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                .addContainerGap(165, Short.MAX_VALUE)
                .addComponent(jLabel49)
                .addGap(18, 18, 18)
                .addComponent(tbConsulta8Pais, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(156, 156, 156))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                .addContainerGap(424, Short.MAX_VALUE)
                .addComponent(bConsulta8)
                .addGap(95, 95, 95))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel23)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel24)
                .addGap(18, 18, 18)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tbConsulta8Pais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel49))
                .addGap(18, 18, 18)
                .addComponent(bConsulta8)
                .addContainerGap(32, Short.MAX_VALUE))
        );

        tabConsulta4.addTab("C-0008", jPanel10);

        bIrGestorTablas.setText("Ir al Gestor de Tablas");
        bIrGestorTablas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bIrGestorTablasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tabConsulta4, javax.swing.GroupLayout.PREFERRED_SIZE, 615, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bIrGestorTablas, javax.swing.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(tabConsulta4, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bIrGestorTablas))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Método que cambia a la vista de la Gestion de las Tablas.
     * 
     * @param evt Evento que hace que se ejecute el método.
     */
    private void bIrGestorTablasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bIrGestorTablasActionPerformed
        new GestionTablas().setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_bIrGestorTablasActionPerformed

    /**
     * Método que ejecuta la consulta 8:
     *
     * @param evt Evento que hace que se ejecute el método.
     */
    private void bConsulta8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bConsulta8ActionPerformed
        if (tbConsulta8Pais.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(this, "El campos que se necesita" +
                    " no está relleno. Por favor, rellene los campos que se" +
                    " indican en rojo.", "Error consulta 8",
                    JOptionPane.ERROR_MESSAGE);
            tbConsulta8Pais.setBackground(new java.awt.Color(255, 102, 102));
        } else {
            try {
                GestorAnimal gAnimal = new GestorAnimal();
                ArrayList<Animal> c1 =
                        gAnimal.getAnimalByPais(tbConsulta8Pais.getText().toUpperCase());

                //Mostar por pantalla la ventana resultado
                ResultadoConsultas r = new ResultadoConsultas();
                String result = "Animales que proceden de " +
                        tbConsulta8Pais.getText().toUpperCase() + ":\n";
                Iterator<Animal> it = c1.iterator();
                if (!it.hasNext()) {
                    result = result.concat("\tLo siento.\n No se han " +
                            "encontrado ocurrencias en la base de datos " +
                            "para el dato proporcionado\n");
                }
                while (it.hasNext()) {
                    Animal a = it.next();
                    result = result.concat("\t" + a.getNombre() + " de " +
                            "la especie " + a.getEspecie() + "\n");
                }
                r.write(result);
                r.setVisible(true);
                r.setDefaultCloseOperation(HIDE_ON_CLOSE);

            } catch (ZooException e) {
            JOptionPane.showMessageDialog(this, e.getMessage(), "Warning " +
                    "Consulta 8", JOptionPane.WARNING_MESSAGE);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Ha ocurrido un error " +
                            "desconocido en la consulta 8.\n" +
                            "Por favor, intentelo de nuevo más tarde.",
                        "Error ejecutando consulta 8",
                        JOptionPane.ERROR_MESSAGE);
            }

            tbConsulta8Pais.setText("");
            tbConsulta8Pais.setBackground(new java.awt.Color(255, 255, 255));
        }
    }//GEN-LAST:event_bConsulta8ActionPerformed

    /**
     * Método que ejecuta la consulta 1:
     *
     * @param evt Evento que hace que se ejecute el método.
     */
    private void bConsulta1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bConsulta1ActionPerformed
        try {
            GestorZoo gZoo = new GestorZoo();
            ArrayList<String> c1 = gZoo.getSalaByZoo();

            //Mostar por pantalla la ventana resultado
            Iterator<String> it = c1.iterator();
            if (!it.hasNext()) {
                JOptionPane.showMessageDialog(this, "Error durante la " +
                        "consulta. Asegurese de que la base de datos no " +
                        "está vacía", "Error consulta 1",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                ResultadoConsultas r = new ResultadoConsultas();
                String result = "";

                while (it.hasNext()) {
                    String next = it.next();
                    try{
                        int aforo = new Integer(next);
                        result = result.concat(" \tAforo Total: "+aforo+"\n");
                    }catch(Exception e){
                        result = result.concat(" ".concat(next));
                    }
                }
                r.write(result);
                writeInforme("Consulta1",result);
                r.setVisible(true);
                r.setDefaultCloseOperation(HIDE_ON_CLOSE);
            }
        } catch (ZooException e) {
            JOptionPane.showMessageDialog(this, e.getMessage(), "Warning " +
                    "Consulta 1", JOptionPane.WARNING_MESSAGE);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Ha ocurrido un error " +
                            "desconocido en la consulta 1.\n" +
                            "Por favor, intentelo de nuevo más tarde.", "Error" +
                    " ejecutando consulta 1",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_bConsulta1ActionPerformed

    /**
     * Método que ejecuta la consulta 2:
     *
     * @param evt Evento que hace que se ejecute el método.
     */
    private void bConsulta2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bConsulta2ActionPerformed
        if (tbConsulta2Cuidador.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(this, "No se ha rellenado toda" +
                    " la información que se necesita. Por favor, " +
                    "rellene el campos que se indican en rojo.", "Error" +
                    " consulta 2", JOptionPane.ERROR_MESSAGE);
            if (tbConsulta2Cuidador.getText().compareTo("") == 0) {
                tbConsulta2Cuidador.setBackground(new java.awt.Color(255,
                        102, 102));
            } else {
                tbConsulta2Cuidador.setBackground(new java.awt.Color(255,
                        255, 255));
            }
        } else {
            GestorHorario ghorarios = new GestorHorario();
            try {
                ArrayList<Horario> c1 =
                        ghorarios.getHorariobyEspecie(
                           tbConsulta2Cuidador.getText().toUpperCase());

                //Mostar por pantalla la ventana resultado
                Iterator<Horario> it = c1.iterator();
                if (!it.hasNext()) {
                    JOptionPane.showMessageDialog(this, "No existe ninguna " +
                            " ocurrencia en la base de datos con la cadena " +
                            "proporcionada", "Warning consulta 2",
                            JOptionPane.WARNING_MESSAGE);
                } else {
                    ResultadoConsultas r = new ResultadoConsultas();
                    String result = "";

                    while (it.hasNext()) {
                        Horario a = it.next();
                        result = result.concat("\t El cuidador con identificador "
                                + tbConsulta2Cuidador.getText().toUpperCase() +
                                " debe alimentar a " + a.getAnimal() + " de " +
                                "la especie " + a.getEspecie() + " a las " +
                                a.getFecha() + " con " +
                                a.getTipoComida() + "\n");
                    }
                    r.write(result);
                    writeInforme("Consulta 2",result);
                    r.setVisible(true);
                    r.setDefaultCloseOperation(HIDE_ON_CLOSE);
                }
            } catch (ZooException e) {
                JOptionPane.showMessageDialog(this, e.getMessage(), "Warning " +
                    "Consulta 2", JOptionPane.WARNING_MESSAGE);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Ha ocurrido un error " +
                            "desconocido en la consulta 2.\n" +
                            "Por favor, intentelo de nuevo más tarde.",
                            "Error " +
                        "ejecutando consulta 2", JOptionPane.ERROR_MESSAGE);
            }
            tbConsulta2Cuidador.setText("");
            tbConsulta2Cuidador.setBackground(new java.awt.Color(255,
                    255, 255)); 
        }
    }//GEN-LAST:event_bConsulta2ActionPerformed

    /**
     * Método que ejecuta la consulta 3:
     *
     * @param evt Evento que hace que se ejecute el método.
     */
    private void bConsulta3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bConsulta3ActionPerformed
        if (tbConsulta3Zoo.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(this, "No se ha rellenado toda" +
                    " la información que se necesita. Por favor, " +
                    "rellene el campo que se indica en rojo.", "Error " +
                    "consulta 3", JOptionPane.ERROR_MESSAGE);
            if (tbConsulta3Zoo.getText().compareTo("") == 0) {
                tbConsulta3Zoo.setBackground(new java.awt.Color(255, 102, 102));
            } else {
                tbConsulta3Zoo.setBackground(new java.awt.Color(255, 255, 255));
            }
        } else {
            GestorAnimal ganimal = new GestorAnimal();
            try {
                ArrayList<Animal> c1 =
                        ganimal.getAnimalesByZoo(tbConsulta3Zoo.getText().toUpperCase());

                //Mostar por pantalla la ventana resultado
                Iterator<Animal> it = c1.iterator();
                if (!it.hasNext()) {
                    JOptionPane.showMessageDialog(this, "No existe ninguna " +
                            " ocurrencia en la base de datos con la cadena " +
                            "proporcionada", "Warning consulta 3",
                            JOptionPane.WARNING_MESSAGE);
                } else {
                    ResultadoConsultas r = new ResultadoConsultas();
                    String result = "";
                    while (it.hasNext()) {
                        Animal a = it.next();
                        result = result.concat(" " + a.getNombre() + " de " +
                                "la especie " + a.getEspecie() + " está en " +
                                "la sala " + a.getSala() + "\n");
                    }
                    r.write(result);
                    r.setVisible(true);
                    r.setDefaultCloseOperation(HIDE_ON_CLOSE);
                }
            } catch (ZooException e) {
                JOptionPane.showMessageDialog(this, e.getMessage(), "Warning " +
                    "Consulta 3", JOptionPane.WARNING_MESSAGE);
            }catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Ha ocurrido un error " +
                            "desconocido en la consulta 3.\n" +
                            "Por favor, intentelo de nuevo más tarde.", "Error " +
                        "ejecutando consulta 3", JOptionPane.ERROR_MESSAGE);
            }
            tbConsulta3Zoo.setText("");
            tbConsulta3Zoo.setBackground(new java.awt.Color(255, 255, 255));
        }
    }//GEN-LAST:event_bConsulta3ActionPerformed

    /**
     * Método que ejecuta la consulta 4:
     *
     * @param evt Evento que hace que se ejecute el método.
     */
    private void bConsulta4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bConsulta4ActionPerformed
        if (tbConsulta4Zoo.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(this, "El campos que se necesita" +
                    " no está relleno. Por favor, rellene los campos que se" +
                    " indican en rojo.", "Error consulta 4",
                    JOptionPane.ERROR_MESSAGE);
            tbConsulta4Zoo.setBackground(new java.awt.Color(255, 102, 102));
        } else {
            GestorTickets gticket = new GestorTickets();
            try {
                int numero = gticket.getTicketsByZoo(tbConsulta4Zoo.getText().toUpperCase());

                //Mostar por pantalla la ventana resultado
                ResultadoConsultas r = new ResultadoConsultas();
                String result = "El número de entradas que quedan por vender" +
                        " en " + tbConsulta4Zoo.getText().toUpperCase() + " son: " + numero;
                r.write(result);
                r.setVisible(true);
                r.setDefaultCloseOperation(HIDE_ON_CLOSE);

            } catch (ZooException e) {
                JOptionPane.showMessageDialog(this, e.getMessage(), "Warning " +
                    "Consulta 4", JOptionPane.WARNING_MESSAGE);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Ha ocurrido un error " +
                            "desconocido en la consulta 4.\n" +
                            "Por favor, intentelo de nuevo más tarde.", "Error " +
                        "ejecutando consulta 4", JOptionPane.ERROR_MESSAGE);
            }
            tbConsulta4Zoo.setText("");
            tbConsulta4Zoo.setBackground(new java.awt.Color(255, 255, 255));
        }
    }//GEN-LAST:event_bConsulta4ActionPerformed

    /**
     * Método que ejecuta la consulta 5:
     *
     * @param evt Evento que hace que se ejecute el método.
     */
    private void bConsulta5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bConsulta5ActionPerformed
        if (tbConsulta5Zoo.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(this, "El campos que se necesita" +
                    " no está relleno. Por favor, rellene los campos que se" +
                    " indican en rojo.", "Error consulta 5",
                    JOptionPane.ERROR_MESSAGE);
            tbConsulta5Zoo.setBackground(new java.awt.Color(255, 102, 102));
        } else {
            GestorSala gsala = new GestorSala();
            try {
                int numero = gsala.getSalasByZoo(tbConsulta5Zoo.getText().toUpperCase());

                //Mostar por pantalla la ventana resultado
                ResultadoConsultas r = new ResultadoConsultas();
                String result = "El número de salas que hay en" +
                        " " + tbConsulta5Zoo.getText().toUpperCase() + " son: " + numero;
                r.write(result);
                r.setVisible(true);
                r.setDefaultCloseOperation(HIDE_ON_CLOSE);

            } catch (ZooException e) {
                JOptionPane.showMessageDialog(this, e.getMessage(), "Warning " +
                    "Consulta 5", JOptionPane.WARNING_MESSAGE);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Ha ocurrido un error " +
                            "desconocido en la consulta 5.\n" +
                            "Por favor, intentelo de nuevo más tarde.", "Error " +
                        "ejecutando consulta 5",
                        JOptionPane.ERROR_MESSAGE);
            }
            tbConsulta5Zoo.setText("");
            tbConsulta5Zoo.setBackground(new java.awt.Color(255, 255, 255));
        }
    }//GEN-LAST:event_bConsulta5ActionPerformed

    /**
     * Método que ejecuta la consulta 6:
     *
     * @param evt Evento que hace que se ejecute el método.
     */
    private void bConsulta6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bConsulta6ActionPerformed
        if (tbConsulta6Ciudad.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(this, "El campos que se necesita" +
                    " no está relleno. Por favor, rellene los campos que se" +
                    " indican en rojo.", "Error consulta 6",
                    JOptionPane.ERROR_MESSAGE);
            tbConsulta6Ciudad.setBackground(new java.awt.Color(255, 102, 102));
        } else {
            GestorZoo gzoo = new GestorZoo();
            try {
                ArrayList<Zoo> c1 =
                        gzoo.getZooByCiudad(tbConsulta6Ciudad.getText().toUpperCase());

                //Mostar por pantalla la ventana resultado
                ResultadoConsultas r = new ResultadoConsultas();
                String result = "Zoos que están en " +
                        tbConsulta6Ciudad.getText().toUpperCase() + ":\n";
                Iterator<Zoo> it = c1.iterator();
                if (!it.hasNext()) {
                    result = result.concat("\tLo siento.\n No se han " +
                            "encontrado ocurrencias en la base de datos " +
                            "para el dato proporcionado\n");
                }
                while (it.hasNext()) {
                    Zoo a = it.next();
                    result = result.concat("\tIdentificador " + a.getId() +
                            " con el nombre " + a.getNombre() + "\n");
                }
                r.write(result);
                r.setVisible(true);
                r.setDefaultCloseOperation(HIDE_ON_CLOSE);

            } catch (ZooException e) {
                JOptionPane.showMessageDialog(this, e.getMessage(), "Warning " +
                    "Consulta 6", JOptionPane.WARNING_MESSAGE);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Ha ocurrido un error " +
                            "desconocido en la consulta 6.\n" +
                            "Por favor, intentelo de nuevo más tarde.", "Error " +
                        "ejecutando consulta 6", JOptionPane.ERROR_MESSAGE);
            }
            tbConsulta6Ciudad.setText("");
            tbConsulta6Ciudad.setBackground(new java.awt.Color(255, 255, 255));
        }
    }//GEN-LAST:event_bConsulta6ActionPerformed

    /**
     * Método que ejecuta la consulta 7:
     *
     * @param evt Evento que hace que se ejecute el método.
     */
    private void bConsulta7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bConsulta7ActionPerformed
        if (tbConsulta7Especialidad.getText().compareTo("") == 0) {
            JOptionPane.showMessageDialog(this, "El campos que se necesita" +
                    " no está relleno. Por favor, rellene los campos que se" +
                    " indican en rojo.", "Error cnsulta 7",
                    JOptionPane.ERROR_MESSAGE);
            tbConsulta7Especialidad.setBackground(new java.awt.Color(255, 102, 102));
        } else {
            try {
                GestorCuidador c = new GestorCuidador();
                ArrayList<Cuidador> c1 =
                        c.getCuidadorByEspecialidad(
                           tbConsulta7Especialidad.getText().toUpperCase());

                //Mostar por pantalla la ventana resultado
                ResultadoConsultas r = new ResultadoConsultas();
                String result = "Cuidadores con la especialidad " +
                        tbConsulta7Especialidad.getText().toUpperCase() + ":\n";
                Iterator<Cuidador> it = c1.iterator();
                if (!it.hasNext()) {
                    result = result.concat("\tLo siento.\n No se han " +
                            "encontrado ocurrencias en la base de datos " +
                            "para el dato proporcionado\n");
                }
                while (it.hasNext()) {
                    Cuidador a = it.next();
                    result = result.concat("\tIdentificador " + a.getId() +
                            "->" + a.getNombre() + " " + a.getApellido1() +
                            " " + a.getApellido2() + "\n");
                }
                r.write(result);
                r.setVisible(true);
                r.setDefaultCloseOperation(HIDE_ON_CLOSE);

            } catch (ZooException e) {
                JOptionPane.showMessageDialog(this, e.getMessage(), "Warning " +
                    "Consulta 7", JOptionPane.WARNING_MESSAGE);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Ha ocurrido un error " +
                            "desconocido en la consulta 7.\n" +
                            "Por favor, intentelo de nuevo más tarde.", "Error " +
                        "ejecutando consulta 7", JOptionPane.ERROR_MESSAGE);
            }
            tbConsulta7Especialidad.setText("");
            tbConsulta7Especialidad.setBackground(new java.awt.Color(255, 255,
                    255));
        }
    }//GEN-LAST:event_bConsulta7ActionPerformed

    private void writeInforme(String nombre, String result){

        try {
            BufferedWriter out = new BufferedWriter(new FileWriter("Informe "+
                    "de la "+ nombre + ".txt"));
            out.write(result);
            out.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, "Error escribiendo el " +
                    "informe de la " + nombre, "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Consultas().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bConsulta1;
    private javax.swing.JButton bConsulta2;
    private javax.swing.JButton bConsulta3;
    private javax.swing.JButton bConsulta4;
    private javax.swing.JButton bConsulta5;
    private javax.swing.JButton bConsulta6;
    private javax.swing.JButton bConsulta7;
    private javax.swing.JButton bConsulta8;
    private javax.swing.JButton bIrGestorTablas;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel49;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JTabbedPane jTabbedPane3;
    private javax.swing.JTabbedPane tabConsulta4;
    private javax.swing.JTextField tbConsulta2Cuidador;
    private javax.swing.JTextField tbConsulta3Zoo;
    private javax.swing.JTextField tbConsulta4Zoo;
    private javax.swing.JTextField tbConsulta5Zoo;
    private javax.swing.JTextField tbConsulta6Ciudad;
    private javax.swing.JTextField tbConsulta7Especialidad;
    private javax.swing.JTextField tbConsulta8Pais;
    // End of variables declaration//GEN-END:variables
}
